﻿@using BE.ModelosIII.Mvc.Models.Util
@model IEnumerable<BE.ModelosIII.Mvc.Models.Scenario.ScenarioListModel>
@{
    ViewBag.Title = "Escenarios";
    Layout = ViewBag.Layout;
}
<section class="utopia-widget">
    <div class="utopia-widget-title">
        <img class="utopia-widget-icon" src="/Content/img/icons/paragraph_justify.png">
        <span>Listado de Escenarios</span>
    </div>
    <div class="utopia-widget-content">
        @if (ViewBag.Actions != null)
        {
            @Html.Partial("_Actions", (IEnumerable<ActionModel>)ViewBag.Actions)
        }
           
        <table class="table datatable table-striped table-bordered">
            <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Tamaño de Caja</th>
                    <th>Acciones</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th>Nombre</th>
                    <th>Tamaño de Caja</th>
                    <th>Acciones</th>
                </tr>
            </tfoot>
            <tbody>
                @foreach (var scenarioModel in Model)
                {
                    <tr>
                        <td>@scenarioModel.Name</td>
                        <td>@scenarioModel.BinSize</td>
                        <td class="actions">
                            <a class="edit runSolution" data-original-title="Encontrar Solución" data-href="@Url.Action("Run", "Run", new { ScenarioId = scenarioModel.Id })" href="javascript:void(0)">
                                <img alt="Encontrar Solucion" src="~/Content/img/icons/play.png"></a>

                            <a class="edit" data-original-title="Ver" href="@Url.Action("View", new { Id = scenarioModel.Id })">
                                <img alt="Ver" src="/Content/img/icons/eye.png"></a>
                            
                            <a class="delete" data-original-title="Borrar" href="@Url.Action("Delete", new { Id = scenarioModel.Id })">
                                    <img alt="Borrar" src="/Content/img/icons/trash_can.png"></a>
                        </td>   
                    </tr>
                }
            </tbody>
        </table>
    </div>
</section>

@section scripts {
    <script type="text/javascript" src="/Content/fancybox/jquery.fancybox.pack.js"></script>
    <script type="text/javascript" src="/Content/js/tables.js"></script>
    <script type="text/javascript">
        $(function () {
            initializeDataTableOnLoad('.datatable');

            var errorUrl = '@Url.Action("ErrorProcessing", "Home")';
            var waitUrl = '@Url.Action("PleaseWait", "Home")';

            $('.runSolution').click(function (ev)
            {
                ev.preventDefault();

                $.fancybox({
                    type: 'ajax',
                    href: waitUrl,
                    dataType: 'html',
                    closeClick: false,
                    closeBtn: false,
                    helpers: {
                        overlay: {
                            closeClick: false
                        }
                    }
                });

                $.getJSON($(this).data('href'), function (result) {
                    if (result.success) {
                        window.location = result.redirectUrl;
                    }
                    else {
                        $.fancybox({
                            type: 'ajax',
                            href: errorUrl,
                            dataType: 'html'
                        });
                    }
                });
            });
        });
    </script>
}

@section css {
    <link href="/Content/fancybox/jquery.fancybox.css" rel="stylesheet" type="text/css" />
}
